import Vue from 'vue';
import Router from 'vue-router';
import index from '../pages/index';
import page1 from '../pages/page1';
import login from '../pages/login'
import notFround from '../pages/notFound';
import ranklist from '../pages/ranklist'
import music from '../pages/music'
import search from '../pages/search'
import phonelogin from '../pages/phonelogin'
import regiter from '../pages/regiter'
import next from '../pages/next'
import fm from '../pages/fm'
import myuser from '../pages/myuser'
import $storage from 'store';
import py from '../pages/py';
import wode from '../pages/wode';
import foucslist from '../pages/foucslist';
import videopag from '../pages/videopag';
import lyric from '../pages/lyric';
import myfloow from '../pages/myfloow'
import mynews from '../pages/mynews'
// const  context=require.context('@/pages',false,/\.vue$/);
// let components = {};
// context.keys().forEach(function (value) {
//  let comp = context(value).default;
//  components[comp.name]=comp;
// });


Vue.use(Router);
const router = new Router({
  routes:[
    {path:'/',redirect:'/index'},
    {path:'/login',name:'login',component:login,},
    {path:'/search',name:'search',component:search,},
    {path:'/music',name:'music',component:music,},
    {path:'/ranklist',name:'ranklist',component:ranklist,},
    {path:'/index',name:'index',component:index, meta: {login: false,bar:true},},
    {path:'/page1',name:'page1',component:page1,},
    {path:'/phonelogin',name:'phonelogin',component:phonelogin,},
    {path:'/regiter',name:'regiter',component:regiter,},
    {path:'/next',name:'next',component:next,},
    {path:'/myuser',name:'myuser',component:myuser,meta:{bar:true}},
    {path:'/fm',name:'fm', meta: {login: true,bar:true},component:fm},
    {path:'/wode',name:'wode', component:wode,meta:{bar:true,login:true}},
    {path:'/py',name:'py', component:py,meta:{bar:true}},
    {path:'/videopag',name:'videopag', component:videopag,meta:{bar:true}},
    {path:'/foucslist',name:'foucslist', component:foucslist,meta:{bar:true}},
    {path:'/lyric',name:'lyric', component:lyric},
    {path:'/myfloow',name:'myfloow', component:myfloow,meta:{bar:true}},
    {path:'/mynews',name:'mynews', component:mynews},
    {path:'/*',name:'notFound',component:notFround,}
  ]
});


router.beforeEach((to, from, next) => {
  if (to.meta.login) {
    if ($storage.get('user')) {
      next();
    } else {
      next('/login');
    }
    // 需要登录
  } else {
    next();
  }
});
export default router;
